using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Impact.Web.Admin.Controls
{
    /// <summary>
    /// code-behind for image picking control
    /// </summary>
    public partial class ImagePicker : System.Web.UI.UserControl
    {

        /// <summary>
        /// override of onload to perform startup functionality
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            ShowPanels();
        }

        /// <summary>
        /// gets or sets the value of the control according to what the user has selected
        /// </summary>
        public string Value
        {
            get
            {
                string output = null;
                if (randomRadio.Checked)
                {
                    output = string.Format("RND:{0}", randomFolder.SelectedFolderPath);
                }
                else if (specificRadio.Checked)
                {
                    output = string.Format("IMG:{0}", specificFile.SelectedFilePath);
                }
                return output;
            }
            set
            {
                if (value == null)
                {
                    noImageRadio.Checked = true;
                }
                else if (value.StartsWith("RND:"))
                {
                    randomRadio.Checked = true;
                    randomFolder.SelectedFolderPath = value.Substring(4);
                }
                else if (value.StartsWith("IMG:"))
                {
                    specificRadio.Checked = true;
                    specificFile.SelectedFilePath = value.Substring(4);
                }
            }
        }

        /// <summary>
        /// event handler for when the user changes which radiobutton is selected
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void RadioCheckedChanged(object sender, EventArgs e)
        {
            ShowPanels();
        }

        /// <summary>
        /// helper to show/hide the appropriate panels due to which radio button is checked
        /// </summary>
        private void ShowPanels()
        {
            if (noImageRadio.Checked)
            {
                randomPanel.Visible = false;
                specificPanel.Visible = false;
            }
            else if (randomRadio.Checked)
            {
                randomPanel.Visible = true;
                specificPanel.Visible = false;
            }
            else if (specificRadio.Checked)
            {
                randomPanel.Visible = false;
                specificPanel.Visible = true;
            }
        }



    }
}